package leader.action;

import java.util.ArrayList;
import java.util.List;

import leader.service.DirectTreatiseService;

import com.opensymphony.xwork2.ActionContext;

import teacher.bean.Award;
import teacher.bean.Teacher;
import teacher.bean.Treatise;
import tools.StringDate;

public class DirectTreatiseTimeAction {
	private List<Treatise> treatise;
	private String datedown;
	private String dateup;
	private int currentpage;
	private int endpage;
	private int count;
	private int pagesize;
	private int flag;
	public List<Treatise> getTreatise() {
		return treatise;
	}
	public void setTreatise(List<Treatise> treatise) {
		this.treatise = treatise;
	}
	public String getDatedown() {
		return datedown;
	}
	public void setDatedown(String datedown) {
		this.datedown = datedown;
	}
	public String getDateup() {
		return dateup;
	}
	public void setDateup(String dateup) {
		this.dateup = dateup;
	}
	
	public int getCurrentpage() {
		return currentpage;
	}
	public void setCurrentpage(int currentpage) {
		this.currentpage = currentpage;
	}
	public int getEndpage() {
		return endpage;
	}
	public void setEndpage(int endpage) {
		this.endpage = endpage;
	}
	public int getCount() {
		return count;
	}
	public void setCount(int count) {
		this.count = count;
	}
	public int getPagesize() {
		return pagesize;
	}
	public void setPagesize(int pagesize) {
		this.pagesize = pagesize;
	}
	
	public int getFlag() {
		return flag;
	}
	public void setFlag(int flag) {
		this.flag = flag;
	}
	public String execute() {
		
		ActionContext.getContext().put("flag", 1);
		ActionContext.getContext().put("date11", this.getDatedown());
		ActionContext.getContext().put("date22", this.getDateup());

		Teacher lea=(Teacher) ActionContext.getContext().getSession().get("leader");
		DirectTreatiseService tre = new DirectTreatiseService();
		StringDate date = new StringDate();
		pagesize = 10;
		count = tre.getCountOfDirectTreatiseByTime(lea, date.StringToDate(datedown),date.StringToDate(dateup));
    	List<Award> awards = new ArrayList<Award>();
    	if(currentpage == 0) {
    		currentpage = 1;
    	}
    	int add = 0;
    	if(count%pagesize != 0) {
    		add = 1;
    	}
    	endpage = count/pagesize + add;
    	if(currentpage > endpage && endpage > 0) {
    		currentpage = endpage;
    	}
    	ActionContext.getContext().put("flag",1);
    	flag = 1;
		treatise = tre.selectSegregateDirectTreatiseByTime(date.StringToDate(datedown),date.StringToDate(dateup), lea, (currentpage-1)*pagesize+1, pagesize);
		return "success";
	}
}
